#[macro_export]
macro_rules! api_add {
    ($fn:ident, $form:ident, $add_fn:expr ) => {
        async fn $fn(
            pool: web::Data<DbPool>,
            form: web::Json<$form>,
        ) -> Result<impl Responder> {
            let added_item = $add_fn(pool, form.into_inner())
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(added_item))
        }
    };
}

#[macro_export]
macro_rules! api_edit {
    ($fn:ident, $form:ident, $edit_fn:expr) => {
        async fn $fn(
            pool: web::Data<DbPool>,
            form: web::Json<$form>,
        ) -> Result<impl Responder> {
            let edited_item = $edit_fn(pool, form.into_inner())
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(edited_item))
        }
    };
}

#[macro_export]
macro_rules! api_delete {
    ($fn:ident, $form:ident, $delete_fn:expr) => {
        async fn $fn(
            pool: web::Data<DbPool>,
            form: web::Json<$form>,
        ) -> Result<impl Responder> {
            let deleted_item = $delete_fn(pool, form.id)
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(deleted_item))
        }
    };
}
